package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.SendAndroidProductAbuselRequest;
import keeto.com.vn.classified.response.SendAndroidProductAbuselResponse;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskSendAndroidProductAbusel extends AbstractTask{
	String ProductID;
	int UserID;
	String Message;
	
	public TaskSendAndroidProductAbusel(ClassifiedListener listener,
			ClassifiedCore core, String productID, int userID, String message) {
		super(listener, core);
		ProductID = productID;
		UserID = userID;
		Message = message;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		SendAndroidProductAbuselRequest request = new SendAndroidProductAbuselRequest();
		request.setAuthKey(authKey);
		request.setProductID(ProductID);
		request.setUserID(UserID);
		request.setMessage(Message);
		SendAndroidProductAbuselResponse response = json.sendAndroidProductAbusel(request);
		for (ClassifiedListener listener : listeners) {
			listener.finishsendAndroidProductAbusel(response.getReturnCode(), response.getResultMsg());
		}
	}

	@Override
	public void timeoutCallback() {
		for (ClassifiedListener l : core.copyAndReconstructListeners(listener)) {
			l.finishsendAndroidProductAbusel(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502, null);
		}
	}

}
